//
//  HMTabBarViewController.m
//  swift-新浪微博OC版-8-29
//
//  Created by 赵玉忠 on 16/8/29.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "HMTabBarViewController.h"
#import "HMNavigationController.h"
#import "HMTabBar.h"
@interface HMTabBarViewController ()

@end

@implementation HMTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    HMTabBar *tabBar = [[HMTabBar alloc]init];
    __weak HMTabBarViewController *weakSelf;
    weakSelf = self;
    tabBar.block = ^{
        NSLog(@"撰写按钮点击，请弹出菜单 %@",weakSelf);
    };
    [self setValue:tabBar forKeyPath:@"tabBar"];
    [self addChildViewControllers];
}

-(void)addChildViewControllers{
    [self addChildViewControllerWithClassName:@"HMHomeTableViewController" andWithTitle:@"首页" andWithImageName:@"tabbar_home"];
    [self addChildViewControllerWithClassName:@"HMMessageTableViewController" andWithTitle:@"消息" andWithImageName:@"tabbar_message_center"];
    [self addChildViewControllerWithClassName:@"HMDiscoverTableViewController" andWithTitle:@"发现" andWithImageName:@"tabbar_discover"];
    [self addChildViewControllerWithClassName:@"HMProfileTableViewController" andWithTitle:@"我" andWithImageName:@"tabbar_profile"];
}

//创建子控制器方法
- (void)addChildViewControllerWithClassName:(NSString*)className andWithTitle:(NSString*)title andWithImageName:(NSString*)imageName
{
    //1.字符串转类
    Class Clz = NSClassFromString(className);
    //2.创建控制器
    UIViewController* vc = [[Clz alloc] init];
    //
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_selected",imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [vc.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    
    HMNavigationController *nav = [[HMNavigationController alloc]initWithRootViewController:vc];
    [self addChildViewController:nav];
    
    
}


@end
